<?php

namespace App\Models\Manger;

use App\Models\CompanyUserDinding;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class MangerDepartment extends Model
{
    protected $table = 'manger_department';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];

    public static function getList(Request $request, $cpid, $status = 0, $isgetall = 0)
    {
        $query = self::where(['cpid' => $cpid,'is_del'=>1])->orderBy('create_at', 'desc');
        if (in_array($status, [1, 2])) {
            $query->where('status', $status);
        }
 

        $department_name = $request->department_name;
        if ($department_name != '') {
            $query->where('department_name', 'like', '%' . $department_name . '%');
        }

        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();

            return ['list' => $list];
        }
    }
}
